package com.dn.dninterface.controller;

import com.dn.dnclientsdk.model.User;
import com.dn.dnclientsdk.utils.SignUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 染染熊
 * @version 1.0
 * @date 2024/3/17 17:56
 */

@RestController
@RequestMapping("/name")
public class NameController {

    @GetMapping("/get")
    public String getNameByGet(String name, HttpServletRequest request) {
//        String accessKey = request.getHeader("accessKey");
//        String secretKey = request.getHeader("secretKey");
//        if (!accessKey.equals("dn") || !secretKey.equals("jt")) {
//            throw new RuntimeException("无权限访问");
//        }
        return "GET 你的名字是：" + name;
    }

    @PostMapping("/post")
    public String getNameByPost(String name) {
        return "Post 你的名字是：" + name;
    }

    @PostMapping("/user")
    public String getUserNameByGet(@RequestBody User user, HttpServletRequest request) {
//        String accessKey = request.getHeader("accessKey");
//        String nonce = request.getHeader("nonce");
//        String body = request.getHeader("body");
//        String timestamp = request.getHeader("timestamp");
//        String sign = request.getHeader("sign");
//
//        if (!accessKey.equals("dn")) {
//            throw new RuntimeException("无权限访问");
//        }
//        if (Long.parseLong(nonce) > 10000) {
////        if (nonce.length() > 10000) {
//            throw new RuntimeException("无权限访问");
//        }
//        boolean overtime = ((System.currentTimeMillis() / 1000) - Long.parseLong(timestamp)) > (5 * 60);
//        if (overtime) {
//            throw new RuntimeException("无权限访问");
//        }
//        String secretKey = "jt";
//        String serverSign = SignUtils.genSign(body, secretKey);
//        if (!serverSign.equals(sign)) {
//            throw new RuntimeException("无权限访问");
//        }
            return "Post 你的名字是：" + user.getUsername();
        }

    }
